<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form action="www.baidu.com" id="form">
    用户名:<input type="text" name="user"/>
    <hr>
    <input type="checkbox" name="copyright">接受协议</input>
    <hr>
    <button>提交</button>
</form>
</body>
<script>
    function query(el) {
        return document.querySelector(el)
    }

    query("#form").addEventListener("submit", function (event) {
        //event 默认参数
        let name = query("[name = user]").value.trim()
        let agree = query("[name = copyright").checked
        event.preventDefault();
        if (name.length < 1 || agree === false) {
            alert("请输入姓名并同意协议")
        }
    })
</script>
</html>
